<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生</title>
    <script src="js/jquery-3.6.3.min.js"></script>
    <script>
        $(function () {
            $.get("grades2.do",function (grades) {
                let g=$("#gradeid");
                $.each(grades,function (i,o) {
                    g.append(new Option(o.gname,o.id));
                    //g.append("<option value='"+o.id+"'>"+o.gname+"</option>")
                })
            });
            $("#telephone").blur(function () {
                if (this.value == "")
                    return;

                let that = this;
                //json的格式改造
                $.post("checkPhone2.do", {phone: $(this).val()}, function (data) {
                    data=JSON.parse(data);
                    if (data.ok) {
                        $(that).next().text("此手机号已经被注册");
                    } else {
                        $(that).next().text("此手机号可以使用");
                    }
                });
                // $.post("checkPhone.do", {phone: $(this).val()}, function (data) {
                //     if (data == "true") {
                //         $(that).next().text("此手机号已经被注册");
                //     } else {
                //         $(that).next().text("此手机号可以使用");
                //     }
                // });
                // $.ajax({
                //    url:'checkPhone.do',
                //     data:{phone:$(this).val()},
                //     method:'post',
                //     //对应服务端out过来的值
                //     success:function (data) {
                //        //alert(data);
                //         if(data=="true"){
                //             $(that).next().text("此手机号已经被注册");
                //         }else{
                //             $(that).next().text("此手机号可以使用");
                //         }
                //     },
                //     error:function (e) {
                //         alert("出现了错误"+e);
                //     }
                // });
            });
        });
    </script>
    <%--<script>
        function checkP(f) {
            if(f.value=="")
                return;
            let xhr=new XMLHttpRequest();
            xhr.onreadystatechange=function (ev) {
                if(xhr.readyState==4&&xhr.status==200){
                    let resp=xhr.responseText;//对应服务器端的write
                    if(resp=="true"){
                        alert("此手机号已经注册");
                    }else{
                        alert("此手机号可以使用");
                    }
                }
            }
            //xhr.open("get","checkPhone.do?phone="+f.value,false);
            xhr.open("get","checkPhone.do?phone="+f.value,true);
            xhr.send(null);
           // xhr.send("phone="+f.value);
        }
    </script>--%>
</head>
<body>
<%@include file="/checkLogin.jsp" %>
<form action="doAddStudent2.jsp" method="post" enctype="multipart/form-data">
    <label>名字</label>
    <input type="text" name="sname" value=""><br>
    <label> 性别</label>
    <select name="sex"><br>
        <option name="男">男</option>
        <option name="女">女</option>
        <option name="妖">妖</option>
    </select>
    <label>电话</label>
    <input type="tel" name="telephone" value="" id="telephone"><span style="color:red"></span><br>
    <label>QQ</label>
    <input type="text" name="qq" value=""><br>
    <label>微信</label>
    <input type="text" name="wechat" value=""><br>
    <label>年级号</label>
    <%--<%
        SqlSession s = MybatisUtil.get();
        GradeDao dao = s.getMapper(GradeDao.class);
        List<Grade> grades = dao.findAll();
        MybatisUtil.close(s);
    %>--%>
    <label>年级号：</label>
    <select id="gradeid" name="gradeid" id="gradeid">
    </select>
    <%--<select id="gradeid" name="gradeid">
        <%
            for (Grade g : grades) {
                //out.print("<option")
        %>
        <option value="<%=g.getId()%>"><%=g.getGname()%>
        </option>
        <%}%>
    </select>--%>
    <br>
    <label>入学时间</label>
    <input type="date" name="enterdate" value=""><br>
    <label>出生城市</label>
    <input type="text" name="fromcity" value=""><br>
    <label>生日</label>
    <input type="date" name="birthday" value=""><br>
    <label>出生地址</label>
    <input type="text" name="address" value=""><br>
    <label>密码</label>
    <input type="text" name="pass" value=""><br>
    <label>身份证照片</label>
    <input type="file" accept="image/*" name="idcardpic"><br>
    <input type="submit" name="提交">
</form>
</body>
</html>
